package com.cakin.newssystem.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @className: ResponseResult
 * @description: 响应消息结果
 *  @param <T> 用于表示返回的数据
 * @date: 2020/5/6
 * @author: cakin
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ResponseResult<T> implements Serializable {

    /**
     * 响应状态回执码
     */
    private Integer status;

    /**
     * 数据体
     */
    private T data;

    /**
     * 响应回执消息
     */
    private String msg;

    public static synchronized <T> ResponseResult<T> e( ResponseCode statusEnum ) {
        return e(statusEnum, null);
    }

    public static synchronized <T> ResponseResult<T> e( ResponseCode statusEnum, T data ) {
        ResponseResult<T> res = new ResponseResult<>();
        res.setStatus(statusEnum.getCode());
        res.setMsg(statusEnum.getMsg());
        res.setData(data);
        return res;
    }

    private static final long serialVersionUID = 8992436576262574064L;
}
